<template>
	<view class="userInfo" v-if="userInfo">
		<img class="bg" :src="userInfo.profile.backgroundUrl" alt="">
		<view  class="personalInfoBox">
			<img   class="avatar" :src="userInfo.profile.avatarUrl" alt="">
			<p class="nickname">{{userInfo.profile.nickname}}</p>
		</view>
	</view>
	
	<view class="userInfo nologin" v-if="!userInfo">
		<view  class="personalInfoBox boxShadow">
			<view v-if="loginStatus === 'true'">
				<p class="loadingtext">加载中...</p>
			</view>
			<view v-else>
				<img class="avatar" src="../../static/头像.png" alt="">
				<p @click="goLogin" class="nickname">去登录<van-icon name="arrow" /></p>
			</view>
		</view>
	</view>
	<!-- 登录状态 -->
	<!-- <view class="" v-if="loginStatus === 'true'">
		<view class="userInfo" v-if="userInfo">
			<img class="bg" :src="userInfo.profile.backgroundUrl" alt="">
			<view  class="personalInfoBox">
				<img   class="avatar" :src="userInfo.profile.avatarUrl" alt="">
				<p class="nickname">{{userInfo.profile.nickname}}</p>
			</view>
		</view>
		
		<view class="userInfo nologin" v-if="!userInfo">
			<view  class="personalInfoBox boxShadow">
				<view >
					<p class="loadingtext">加载中...</p>
				</view>
			</view>
		</view>
	</view> -->
	
	<!-- 未登录状态 -->
	<!-- <view class=""  v-if="loginStatus === ' '">
		<view class="userInfo nologin">
			<view  class="personalInfoBox boxShadow">
					<img class="avatar" src="../../static/头像.png" alt="">
					<p @click="goLogin" class="nickname">去登录<van-icon name="arrow" /></p>
			</view>
		</view> 
	</view> -->
</template>

<script setup>
import { onMounted, ref } from 'vue';
import { getLoginStatusApi, userSubcountApi } from '../../api/userApi.js'

let userInfo = ref()
let loginStatus = ref(localStorage.getItem('loginStatus'))

// console.log(loginStatus.value)

// 登录跳转
const goLogin = () => {
	uni.navigateTo({
		url: "/pages/user/user"
	})
}

onMounted(()=>{
	
	// 获取用户信息
	
	let cookie = localStorage.getItem('cookie')
	// console.log(cookie);
	
	if (cookie !== null) {
		// 获取本地cookie
		// 请求用户信息
		getLoginStatusApi(cookie).then((res)=>{
			userInfo.value = res.data.data
			// console.log(res.data.data);
			
			loginStatus.value = true

		})
	}else{
		userInfo.value = null
		
		loginStatus.value = false
	}
	
	
	
	
	// userSubcountApi().then((res)=>{
	// 	console.log(res);
	// })
})



</script>

<style lang="scss" scoped>
@import url('mine.scss');
</style>
